(function ($) {
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
})(jQuery);
// 校验邮箱


//校验密码（不少于6位的非纯数字）
$('#password').blur(function(){
    var regPassword = new RegExp(/^(?!(?:\d+|[a-zA-Z]+)$)[\da-zA-Z]{6,}$/);
    var password = $('#password').val();
    if (!password.match(regPassword)) {
        $('.err-info').html('密码格式应为不少于6位的非纯数字');
        return false;
    }else{
         $('.err-info').html('');
     }
});
//注册
$('.register-btn').click(function(){
    var regEmail = new RegExp(/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/);
    var regPassword = new RegExp(/^(?!(?:\d+|[a-zA-Z]+)$)[\da-zA-Z]{6,}$/);
    var email = $('#email').val();
    var password = $('#password').val();
    var confirm = $('#confirm').val();
    var wlink = $.getUrlParam('wlink');
    if (!email.match(regEmail)) {
        $('.err-info').html('请输入正确的邮箱');
        return false;
    }else if (!password.match(regPassword)) {
         $('.err-info').html('密码应为6位以上非纯数字');
         return false;
     }else if(!(password==confirm)){
        $('.err-info').html('与设置密码不一致，请确认您的密码');
        return false;
    }
    else{
        $('.err-info').html('');
    }
    var data = {
        email : email,
        password : md5(password),
        repassword:md5(confirm),
        wlink:wlink
    }
    //发送用户数据
    $.ajax({
        url: '/registration.json',
        type: 'post',
        data:JSON.stringify(data),
        contentType:'application/json;charset=UTF-8',
        crossDomain: true,
        success: function (data) {
            $('.err-info').html('注册成功,请去邮箱验证');
            $('.cover').css('display','block');
        },
        error:function (err) {
            $('.err-info').html(JSON.parse(err.responseText).errors[0].msg);
        }
    });
});
    //
    $('.email-name').html($('#email').val());
    $('.cover').click(function(){
        $('.cover').css('display','none');
    });

//邮箱验证
$('.to-send-email').click(function(){
    $.ajax({
        url:'/user/send_activate_mail.json',
        type:'get',
        dataType:"json",
        success:function(data){
            $('.cover').css('display','block');
            // $('.email-main').css('display','block');
        },
        error:function(err){
            $('.err-info').html(JSON.parse(err.responseText).errors[0].msg);
        }
    });
});